package com.neusoft.tyut.elm.controller;

import java.io.IOException;

import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Servlet implementation class AccessCounterServlet
 */
@WebServlet("/admin/ac.servlet")
public class AccessCounterServlet extends HttpServlet {
	
	public static final  String  AccessCounterName= "AccessCounterName";
	
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public AccessCounterServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
//		获得 次数
		ServletContext  application =  request.getServletContext();
		Object obj =  application.getAttribute(AccessCounterName );
		int times = 0 ;
		if( obj == null  ) {
			times = 0 ;
		}else {
			times = (Integer)obj;
		}
//		次数++；
		times++;
//		写会去
		application.setAttribute(AccessCounterName, times);		
		
		response.getWriter().append("AccessCounterName: ").append( times+""  );
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
	}

}
